package com.jeff.tianti.cms.dao;

import com.jeff.tianti.cms.dto.QuestionsAnswersQueryDTO;
import com.jeff.tianti.cms.dto.font.AnswersTo;
import com.jeff.tianti.common.dao.CustomBaseSqlDaoImpl;
import com.jeff.tianti.common.entity.PageModel;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.jeff.tianti.cms.entity.Answers;
import com.jeff.tianti.cms.dto.AnswersQueryDTO;
import org.apache.commons.lang3.StringUtils;

/**
 * @author xujianfang
 * @desc AnswersDaoImpl类 
 * @date 2019-07-19
 */

public class AnswersDaoImpl extends CustomBaseSqlDaoImpl implements AnswersDaoCustom  {

    public PageModel<Answers> queryAnswersPage(AnswersQueryDTO answersQueryDTO){
         Map<String,Object> map = new HashMap<String,Object>();
         StringBuilder hql = new StringBuilder();
         hql.append("select t from Answers t ");
         return this.queryForPageWithParams(hql.toString(),map,answersQueryDTO.getCurrentPage(),answersQueryDTO.getPageSize());
    }

    public List<Answers> queryAnswersList(AnswersQueryDTO answersQueryDTO){
         Map<String,Object> map = new HashMap<String,Object>();
         StringBuilder hql = new StringBuilder();
         hql.append("select t from Answers t ");
         return this.queryByMapParams(hql.toString(),map);
    }

    @Override
    public  PageModel<Answers> queryAnswersPages(QuestionsAnswersQueryDTO questionsAnswersQueryDTO) {
        Map<String,Object> map = new HashMap<String,Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from Answers t where 1 = 1 ");
        if (questionsAnswersQueryDTO != null) {
            String auditFlag = questionsAnswersQueryDTO.getAuditFlag();
            if (StringUtils.isNotBlank(auditFlag) && !"-1".equals(auditFlag)) {
                hql.append(" and t.auditFlag = :auditFlag ");
                map.put("auditFlag", auditFlag);
            }
        }
        return this.queryForPageWithParams(hql.toString(),map,questionsAnswersQueryDTO.getCurrentPage(),questionsAnswersQueryDTO.getPageSize());

    }

    @Override
    public List<Answers> findAllByQuestionsAnswersId(String id) {
        Map<String,Object> map = new HashMap<String,Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from Answers t where t.questionsAnswersId = :questionsAnswersId ");
        map.put("questionsAnswersId", id);
        return this.queryByMapParams(hql.toString(),map);
    }

    @Override
    public PageModel<Answers> findPageByAnswersTo(AnswersTo answersTo) {
        return null;
    }


}